package simpleFactory.order;

import com.sun.scenario.effect.impl.prism.ps.PPSZeroSamplerPeer;
import simpleFactory.pizza.CheesePizza;
import simpleFactory.pizza.GreekPizza;
import simpleFactory.pizza.PepperPizza;
import simpleFactory.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2023-03-07
 * Time: 20:44
 */

//订购披萨
public class OrderPizza {

//    //构造器
//    public OrderPizza(){
//        Pizza pizza = null;
//        String orderType;
//        do {
//            //现在提供这两种去给用户订购的披萨
//            orderType = gettype();
//            if (orderType.equals("greek")){
//                pizza = new GreekPizza();
//                //已经创建好披萨了 设置一个名字
//                pizza.setName("希腊披萨");
//            }else if (orderType.equals("cheese")){
//                pizza = new CheesePizza();
//                pizza.setName("奶酪披萨");
//            //增加了新的披萨 那么逻辑的判断也要新增一个
//            }else if (orderType.equals("pepper")){
//                pizza = new PepperPizza();
//                pizza.setName("胡椒披萨");
//            }else{
//                break;
//            }
//            //输出披萨制作过程
//            pizza.prepare();
//            pizza.bake();
//            pizza.cut();
//            pizza.box();
//        }while (true);
//    }

    //工厂创建好了 但是还不知道怎么调用
    //构造器
    public OrderPizza(SimpleFactory simpleFactory){
        setFactory(simpleFactory);
    }

    //定义一个简单的工厂对象
    SimpleFactory simpleFactory;
    Pizza pizza = null;
    public void setFactory(SimpleFactory simpleFactory){
        String orderType = ""; //用户传来的披萨类型

        this.simpleFactory = simpleFactory; //设置简单工厂对象

        do {
            orderType = gettype();
            pizza =this.simpleFactory.createPizza(orderType);

            //输出披萨信息
            if (pizza != null){
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else {
                System.out.println("没有这个披萨");
                break;
            }
        }while (true);
    }

    //写一个方法 可以获取用户希望订购的披萨种类
    private String gettype() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type:");
            String str = strin.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }

}
